li1 = [['牛奶', 5], ['衣服', 200], ['家具', 500]]
li2 = []  # 购物车
money = 5000

while True:
    a = input("\n请输入你要买的商品 (输入'结账'结账, 'Q/q'离开): ")

    if a in ['Q', 'q']:
        print("再见！")
        break
    elif a == '结账':
        total = sum(item[1] for item in li2)
        print(f"总计: ¥{total}")
        if money >= total:
            money -= total
            print("购买成功！")
            li2 = []  # 清空购物车
        else:
            print("余额不足！")
    else:
        # 查找商品
        for b in li1:
            if b[0] == a:
                li2.append(b)
                print(f"已添加 {a} 到购物车")
                break
        else:
            print("商品不存在！")
